export default {
    data() { 
        return {
            formData: new FormData()
        }
    },
    methods: {
        handleUploadLimit(file) {
            const isJPG = file.type === 'image/jpeg';
            const isPNG = file.type === 'image/png'
            const isLt2M = file.size / 1024 / 1024 < 10;

            if (!(isJPG || isPNG)) {
                this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 10MB!');
            }
            return (isJPG || isPNG) && isLt2M;
        }
    },
    computed: {
        hasFile() {
            return (file, formData) => {
                if (formData.get('file')) {
                    return formData.set('file', file.file)
                }
                return formData.append("file", file.file);
            }
        }
    }
}